import Taro, { Component, Config, showToast } from '@tarojs/taro'
import { Provider } from '@tarojs/mobx'
import '@tarojs/async-await';
import 'taro-ui/dist/style/index.scss' // 全局引入一次即可
import Index from './pages/index'
import Stores from './store/Stores';
import { companyName, getToken, getUserInfo, getWechatCode, setUserInfo, showToast } from './utils/common'



import './app.scss'

const store = {
  stores: new Stores()
};

class App extends Component {
  state = {
    pagesArr: [
      { id: 1, path: 'pages/index/index', isLogin: false, title: '渔满天下' },
      // { id: 1, path: 'pages/index/fishKnow', isLogin: false, title: '去了解' },
      // { id: 1, path: 'pages/other/block', isLogin: false, title: '空白页' },
      { id: 2, path: 'pages/components/imgUpload', isLogin: false, title: '图片上传' },
      { id: 3, path: 'pages/vr/vr', isLogin: true, title: '鱼塘VR' },
      { id: 4, path: 'pages/fish/fish', isLogin: false, title: '养鱼啦' },
      { id: 5, path: 'pages/fish/buy', isLogin: true, title: '立即购买' },
      { id: 6, path: 'pages/fish/buySuccess', isLogin: true, title: '购买成功' },
      { id: 7, path: 'pages/fish/detail', isLogin: false, title: '联养详情' },
      { id: 8, path: 'pages/fish/buyLog', isLogin: false, title: '购买记录' },
      { id: 9, path: 'pages/share/index', isLogin: true, title: '我的二维码' },
      { id: 12, path: 'pages/share/qrCode', isLogin: true, title: '关注我们' },
      { id: 10, path: 'pages/login/login', isLogin: false, title: '登录注册' },
      { id: 11, path: 'pages/mine/mine', isLogin: false, title: '我的' },
      { id: 11, path: 'pages/mine/sign', isLogin: true, title: '签到' },
      { id: 12, path: 'pages/mine/fish', isLogin: true, title: '我的鱼塘' },
      { id: 12, path: 'pages/mine/fishDetail', isLogin: true, title: '鱼塘详情' },
      { id: 12, path: 'pages/mine/profit', isLogin: true, title: '我的收益' },
      { id: 12, path: 'pages/mine/cash', isLogin: true, title: '立即提现' },
      { id: 12, path: 'pages/mine/cashSuccess', isLogin: true, title: '提现成功' },
      { id: 12, path: 'pages/mine/cashRecord', isLogin: true, title: '提现记录' },
      { id: 12, path: 'pages/mine/edit', isLogin: true, title: '编辑资料' },
      { id: 12, path: 'pages/mine/team', isLogin: true, title: '我的团队' },
      { id: 12, path: 'pages/mine/teamMember', isLogin: true, title: '我的团队-下级成员' },
      { id: 12, path: 'pages/mine/auth', isLogin: true, title: '实名认证' },
      { id: 12, path: 'pages/mine/authed', isLogin: true, title: '实名认证' },
      { id: 12, path: 'pages/mine/authSuccess', isLogin: true, title: '认证成功' },
      { id: 12, path: 'pages/mine/upgrade', isLogin: true, title: '认证成功' },
      { id: 12, path: 'pages/mine/bank', isLogin: true, title: '我的银行卡' },
      { id: 12, path: 'pages/mine/bankAdd', isLogin: true, title: '添加银行卡' },
      { id: 12, path: 'pages/mine/address', isLogin: true, title: '我的收货地址' },
      { id: 12, path: 'pages/mine/addressAdd', isLogin: true, title: '添加收货地址' },
      { id: 12, path: 'pages/mine/help', isLogin: false, title: '帮助中心' },
      { id: 12, path: 'pages/mine/helpDetail', isLogin: false, title: '帮助详情' },
      { id: 12, path: 'pages/mine/aboutus', isLogin: false, title: '关于我们' },
      { id: 12, path: 'pages/mine/company', isLogin: false, title: '公司简介' },
      { id: 12, path: 'pages/mine/contactus', isLogin: false, title: '联系我们' },
      { id: 12, path: 'pages/mine/setting', isLogin: false, title: '设置' },
      { id: 12, path: 'pages/mine/editPhone', isLogin: true, title: '更换手机号' },
      { id: 12, path: 'pages/dynamic/index', isLogin: false, title: '动态资讯' },
      { id: 12, path: 'pages/dynamic/detail', isLogin: false, title: '动态资讯' },
      { id: 1000, path: 'pages/components/form', isLogin: false, title: '表单' }
    ]
  }

  componentWillMount() {
    
    // console.log(this.state.pagesArr)

    let userInfo = getUserInfo() || {}

    Taro.setNavigationBarTitle({ title: companyName })

    /* let userInfo_static = {
      avatar: "http://thirdwx.qlogo.cn/mmopen/ajNVdqHZLLC0bOVHThNicXuHVS5pvkxOFEibbJHxjnibYVChibakZsyvasT4kFQLzmMCR7cJf5cia8a24M5B8WA8mYg/132",
      id: "58594c2b-840b-46d6-8755-08d797d9b729",
      isVerify: false,
      nickName: "云在天上飘",
      subscribe: "1",
      token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyMDNDOTkxNTk4MzM2RjE4QTNERDU1RTIzQkY2RDdFQkM1OTBDOTA0MTg0NUYzRUY5MTE2NzUwNUMwQzAyRkNDMzJCRjdFNjg3MTBENTQwRSIsImlhdCI6IjE1ODgyMTIyOTAiLCJuYmYiOiIxNTg4MjEyMjkwIiwiZXhwIjoiMTU4ODgxNzA5MCIsImlzcyI6IkFQSSIsImF1ZCI6IlVzZXIiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiMTg5ODc0MjI1NzAifQ.4Lw8p_z5OWkpklSZxDPHMXeBX1b1OfDz9BuZLuxiyZQ",
      userPhone: '',
      userSex: "1"
    }

     setUserInfo(userInfo_static)

     console.log(userInfo) */

    /* if (Object.keys(userInfo).length > 0 && userInfo.token) {
      let { userStore } = store.stores
      userStore.getUserInfoAsync({
        callback: res => {
          res.token = userInfo.token
          res.loginTime = userInfo.loginTime
          res.expire = userInfo.expire
          setUserInfo(res)
        }
      })
    } */
  }

  config: Config = {
    pages: [
      'pages/index/index',
      // 'pages/index/fishKnow',
      // 'pages/other/block',
      'pages/components/imgUpload',
      'pages/vr/vr',
      'pages/fish/fish',
      'pages/fish/buy',
      'pages/fish/buySuccess',
      'pages/fish/detail',
      'pages/fish/buyLog',
      'pages/share/index',
      'pages/share/qrCode',
      'pages/login/login',
      'pages/components/form',
      'pages/mine/mine',
      'pages/mine/sign',
      'pages/mine/fish',
      'pages/mine/fishDetail',
      'pages/mine/profit',
      'pages/mine/cash',
      'pages/mine/cashSuccess',
      'pages/mine/cashRecord',
      'pages/mine/edit',
      'pages/mine/team',
      'pages/mine/teamMember',
      'pages/mine/auth',
      'pages/mine/authed',
      'pages/mine/authSuccess',
      'pages/mine/upgrade',
      'pages/mine/bank',
      'pages/mine/bankAdd',
      'pages/mine/address',
      'pages/mine/addressAdd',
      'pages/mine/help',
      'pages/mine/helpDetail',
      'pages/mine/aboutus',
      'pages/mine/company',
      'pages/mine/contactus',
      'pages/mine/setting',
      'pages/mine/editPhone',
      'pages/dynamic/index',
      'pages/dynamic/detail',
    ],
    window: {
      backgroundTextStyle: 'light',
      navigationBarBackgroundColor: '#fff',
      navigationBarTitleText: companyName,
      navigationBarTextStyle: 'black'
    },
    debug: false
  }

  componentDidShow() {
    
    Taro.setNavigationBarTitle({ title: companyName })
  }

  componentDidHide() { }

  componentDidCatchError() { }

  // 在 App 类中的 render() 函数没有实际作用
  // 请勿修改此函数
  render() {
    return (
      <Provider store={store}>
        <Index />
      </Provider>
    )
  }
}

Taro.render(<App />, document.getElementById('app'))
